//2009/08/01 22:12:26
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

using namespace std;

class Salary
{
public:
	int howMuch(vector<string> ar, vector<string> de, int wage)
	{
		double hours = 0.0;
		int n = ar.size();
		for(int i=0; i<n; i++)
		{
			int a1,b1,c1;
			int a2,b2,c2;
			char dd;
			stringstream s1(ar[i]);
			stringstream s2(de[i]);
			s1 >> a1 >> dd >> b1 >> dd >> c1;
			s2 >> a2 >> dd >> b2 >> dd >> c2;
			long long a = a1*3600 + b1*60 + c1;
			long long b = a2*3600 + b2*60 + c2;
			long long c = 18*3600;
			long long d = 6*3600;
			if(a <d)
			{
				if(b<d)
					hours += abs(a-b)*1.5;
				else if(b>=d && b<c)
					hours += abs(a-d)*1.5 + abs(b-d);
				else
					hours += (abs(a-d)+abs(b-c))*1.5 + abs(d-c);
			}
			if(a>=d && a<c)
			{
				if(b<c)
					hours += abs(a-b);
				else
					hours += abs(a-c) + abs(b-c)*1.5;
			}
			if(a>=c)
				hours += abs(a-b)*1.5;
		}
		return (int)(hours*wage/3600);
	}
};
